<template>
    <div>
        <h1>注册</h1>
        <van-field type="text" label="名称" placeholder="名称" v-model="name"/>
        <van-field type="password" label="密码" placeholder="密码" v-model="password"/>
        <van-button type="primary" @click="add_user">注册</van-button>

        <h1>登录</h1>
        <van-field type="text" label="名称" placeholder="请输入名称" v-model="username"/>
        <van-field type="password" label="密码" placeholder="请输入密码" v-model="passwords"/>
        <van-button type="primary" @click="get_user">登录</van-button>


    </div>
</template>

<script>
export default {
   data () {
      return {
          //注册绑定
          name:'',
          password:'',
          //登录绑定
          username:'',
          passwords:'',
      };
   },

    methods: {
        //注册账户
        add_user:function(){
            if (this.password == ''){
                this.$toast.fail('密码不能为空');
                return false;
            }
            this.axios.post(this.localhost+'add_admin/',this.qs.stringify({'name':this.name,'password':this.password})).then(res=>{
                if (res.data.code == 200){
                    this.$toast.success(res.data.meg);
                }else{
                    this.$toast.fail(res.data.meg);
                }
            })
        },
        //用户登录
        get_user:function(){
            if (this.passwords == ''){
                this.$toast.fail('空密码是登不上去的哦~');
                return false;
            }
            this.axios.get(this.localhost+'get_admin/',{params:{
                name:this.username,
                password:this.passwords
            }}).then(res=>{
                if (res.data.code == 200){
                    this.$toast.success(res.data.meg);
                    this.$toast.success('用户名'+res.data.name+'---密码'+res.data.password);
                }else{
                    this.$toast.fail(res.data.meg);
                }
            })
        },
       },

    computed: {

       },

    created () {

       },

    mounted() {

       },

    components: {

       }
}
</script>
<style lang='css' scoped>

</style>